﻿using System;
using System.Drawing;
using Gaia.WebWidgets;
using ASP = System.Web.UI.WebControls;

public abstract class ToolboxItemBase : Panel
{
    private readonly DynamicImage _toolboxDynamicImage;
    private readonly Label _toolBoxLabel;

    protected ToolboxItemBase()
    {
        _toolboxDynamicImage = new DynamicImage();
        _toolBoxLabel = new Label();
    }

    protected override void OnInit(EventArgs e)
    {
        //add aspects and initialization
        Aspects.Add(new AspectDraggable(null, Rectangle.Empty, true, false, 0.5M, null, ToolBoxItemType.FullName));

        _toolboxDynamicImage.RetrieveImage += _toolBoxIcon_RetrieveImage;

        CssClass = "toolboxItem";
        _toolBoxLabel.Text = ToolBoxItemType.Name;

        base.OnInit(e);
    }

    protected override void OnLoad(EventArgs e)
    {
        if (!Page.IsPostBack)
            _toolboxDynamicImage.ImageId = Guid.NewGuid().ToString().Replace("-", "");
        
        EnsureChildControls();
        base.OnLoad(e);
    }

    protected override void CreateChildControls()
    {
        Controls.Add(_toolBoxLabel);
        //Controls.Add(_toolboxDynamicImage);

        base.CreateChildControls();
    }

    void _toolBoxIcon_RetrieveImage(object sender, DynamicImage.RetrieveImageEventArgs e)
    {
        e.Image = ToolBoxImage;
    }

    public System.Drawing.Image ToolBoxImage { get; set; }
    public Type ToolBoxItemType { get; set; }
}
